package com.business.fallback;

import com.business.api.TestApi;
import com.comm.enums.FeignErrorEnum;
import com.comm.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author mis_wu
 * @date 2022/6/18 15:22
 * @todo TestApi服务熔断处理
 */
@Slf4j
@Component
public class TestApiFallbackImpl implements FallbackFactory<TestApi> {

    private static class FallbackTestApi implements TestApi {

        private final Throwable throwable;

        private FallbackTestApi(Throwable throwable){
            this.throwable = throwable;
        }

        @Override
        public ResponseResult<Object> testFeign(String name) {
            log.error("服务熔断方法:testFeign,参数:{},异常信息:{},{}",name,throwable.getMessage(),throwable);
            return ResponseResult.feignError(FeignErrorEnum.FEIGN_SERVE_ERROR,throwable);
        }

    }

    @Override
    public TestApi create(Throwable throwable) {
        return new FallbackTestApi(throwable);
    }
}
